-
-
Notifications
You must be signed in to change notification settings - Fork 362
feat(Table): add FitAllColumnWidth instance method #6857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis PR introduces a new FitAllColumnWidth API that invokes a JavaScript routine to auto-fit every column in the table and refines the cell width calculation to account for border sizes. Sequence diagram for FitAllColumnWidth API invocationsequenceDiagram
participant CSharp as Table (C#)
participant JS as Table.razor.js
CSharp->>JS: Invoke fitAllColumnWidth(id)
JS->>JS: Get table by id
alt Table found
JS->>JS: For each .col-resizer in table
JS->>JS: autoFitColumnWidth(table, col)
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new instance method FitAllColumnWidth to the Table component that automatically fits all column widths to their content. The feature allows programmatic control over column width optimization for all columns at once.
- Added a new public method
FitAllColumnWidth()to the Table component C# class - Implemented corresponding JavaScript function
fitAllColumnWidth()that iterates through all resizable columns and applies auto-fit logic - Updated the calculation logic to include border widths in column width calculations
- Bumped version from 9.11.1-beta06 to 9.11.1
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Table.razor.cs | Adds the public FitAllColumnWidth method that calls JavaScript interop |
| Table.razor.js | Implements fitAllColumnWidth function and improves width calculation logic |
| BootstrapBlazor.csproj | Updates version number from beta to release |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor/Components/Table/Table.razor.js:788-789` </location>
<code_context>
const cellStyle = getComputedStyle(cell);
- const width = div.offsetWidth + parseFloat(cellStyle.getPropertyValue('padding-left')) + parseFloat(cellStyle.getPropertyValue('padding-right'));
- div.remove();
+ const width = div.offsetWidth + parseFloat(cellStyle.getPropertyValue('padding-left')) + parseFloat(cellStyle.getPropertyValue('padding-right')) + parseFloat(cellStyle.getPropertyValue('border-left-width')) + parseFloat(cellStyle.getPropertyValue('border-right-width')) + 1;
return width;
}
</code_context>
<issue_to_address>
**suggestion:** Adding a hardcoded '+ 1' to width calculation may introduce inconsistencies.
This change may cause off-by-one errors or misalignment. If it's addressing a specific rendering issue, please document the rationale or explore a more reliable fix.
```suggestion
// Removed hardcoded '+ 1' to avoid off-by-one errors. If subpixel rendering causes issues, consider using Math.ceil().
const width = Math.ceil(
div.offsetWidth +
parseFloat(cellStyle.getPropertyValue('padding-left')) +
parseFloat(cellStyle.getPropertyValue('padding-right')) +
parseFloat(cellStyle.getPropertyValue('border-left-width')) +
parseFloat(cellStyle.getPropertyValue('border-right-width'))
);
return width;
```
</issue_to_address>
### Comment 2
<location> `src/BootstrapBlazor/Components/Table/Table.razor.js:788-789` </location>
<code_context>
const width = div.offsetWidth + parseFloat(cellStyle.getPropertyValue('padding-left')) + parseFloat(cellStyle.getPropertyValue('padding-right')) + parseFloat(cellStyle.getPropertyValue('border-left-width')) + parseFloat(cellStyle.getPropertyValue('border-right-width')) + 1;
return width;
</code_context>
<issue_to_address>
**suggestion (code-quality):** Inline variable that is immediately returned ([`inline-immediately-returned-variable`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/JavaScript/Default-Rules/inline-immediately-returned-variable))
```suggestion
return div.offsetWidth + parseFloat(cellStyle.getPropertyValue('padding-left')) + parseFloat(cellStyle.getPropertyValue('padding-right')) + parseFloat(cellStyle.getPropertyValue('border-left-width')) + parseFloat(cellStyle.getPropertyValue('border-right-width')) + 1;
```
<br/><details><summary>Explanation</summary>Something that we often see in people's code is assigning to a result variable
and then immediately returning it.
Returning the result directly shortens the code and removes an unnecessary
variable, reducing the mental load of reading the function.
Where intermediate variables can be useful is if they then get used as a
parameter or a condition, and the name can act like a comment on what the
variable represents. In the case where you're returning it from a function, the
function name is there to tell you what the result is, so the variable name
is unnecessary.
</details>
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6857 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 739 739
Lines 31755 31758 +3
Branches 4466 4466
=========================================
+ Hits 31755 31758 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #6773
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Enable programmatic auto-fitting of all table columns via a new FitAllColumnWidth method and enhance cell width calculation for accuracy.
New Features:
Enhancements: